'Copyright 2006 James Downey
Imports System.Xml

Public Class Order

    '<!--
    'order element - used to specify a sort order
    '-->
    '<ElementType name='order' content='eltOnly' model='closed'>
    '  <AttributeType name='attribute' dt:type='string' required='yes' />
    '  <AttributeType name='descending' dt:type='boolean' required='no' 
    '                 default='false' />
    '  <!-- -->
    '  <attribute type='attribute' />
    '  <attribute type='descending' />
    '</ElementType>

    Public Attribute As String
    Public Descending As Boolean = False

    Public Sub New()
        '
    End Sub

    Public Sub New(ByVal Attribute As String, Optional ByVal Desending As Boolean = False)
        Me.Attribute = Attribute
        Me.Descending = Descending
    End Sub

    Public Sub New(ByVal OrderNode As XmlNode)
        Me.Attribute = OrderNode.Attributes("attribute").Value
        If Not OrderNode.Attributes("descending") Is Nothing Then
            If OrderNode.Attributes("descending").Value = "true" Or OrderNode.Attributes("descending").Value = "1" Then
                Me.Descending = True
            End If
        End If
    End Sub

    Public Overrides Function ToString() As String
        If Descending Then
            Return "<D> " & Me.Attribute
        Else
            Return "<A> " & Me.Attribute
        End If
    End Function

    Public Function ToXML() As String
        Dim strXml As String
        strXml = "<order attribute='" & Me.Attribute & "' "
        If Descending Then
            strXml &= "descending='true' "
        End If
        strXml &= "/>"
        Return strXml
    End Function

End Class
